$(function(){
	var a = ym.getQueryStringByName('a');
	if(a == 2){
		$('#goBackIcon').attr('href','javascript:history.go(-1)');
	}else{
		$('#goBackIcon').attr('href','yuerjiangzuo.html');
	}
	
	
	var doc,use;
	ym.ajax({
		url : "/user/getUser",
		async : false,
		success : function(data){
			if(data.res == 1){
				var html ="";
				if(data.obj.type == 1){
					use = data.obj.userId;
					ym.ajax({
						url: "/askDoctor/queryDoctorId",
						param:{
							userId:use
						},
						success: function (data){
						   doc = data.obj;
						   window.location.href="Doctor.html?doctorid="+doc+"&userid="+use+"a=2";
						}
					});
				}else{
						
				}
			}else{console.log("没有获取到当前用户的身份")}
			
		}
	});
	
	ym.getUser();
	var doctorFormHTML="";
	var doctorListsHTML="";
	/*获取推荐医生*/
	function getTJDcotors(){
		ym.ajax({
			url: "/askDoctor/queryDoctorOrderByQuota",
			param:{},
			success: function (data) {
				console.log(data);
			   if(data.obj){
			   	childList=data.obj;
			   	var swiper = new Swiper('.swiper-container', {
                      slidesPerView: 2,
                      centeredSlides: false,
                      spaceBetween: 10,
                      pagination: {
                        el: '.swiper-pagination',
                        type: 'fraction',
                      },
                      // navigation: {
                      //   nextEl: '.swiper-button-next',
                      //   prevEl: '.swiper-button-prev',
                      // },
                      virtual: {
                        slides: (function () {
                          var slides = [];
                          for (var i = 0; i < data.obj.length; i ++) {
                            slides.push("<li class='doctor-vip-content' userId='"+data.obj[i].userId+"'>"+
											"<div class='doctor-vip-tab'>"+
												"<div class='doctor-tab-tip'><span>"+data.obj[i].douctorConsultTypeName+"</span></div>"+
												"<div class='doctor-tab-img'><img src='"+data.obj[i].headimgurl+"'></div>"+
												"<div class='doctor-tab-name'><p>"+data.obj[i].doctorRealName+"</p></div>"+
												"<div class='doctor-tab-desc'><span>"+data.obj[i].des+"</span></div>"+
												"<div class='doctor-tab-meCount'><p>今日还剩<span>"+data.obj[i].quota+"</span>个提问名额</p></div>"+
											"</div>"+
										"</li>");
                          }
                          return slides;
                        }()),
                      },
                    });
			   	// $('.doctor-vip').append(doctorFormHTML);
			   }
			}
		});
	}
	/*查询所有医生列表*/
	function getDoctorList(){
		ym.ajax({
			url: "/askDoctor/queryAllYmDoctor",
			param:{},
			success: function (data) {
				console.log(data);
			   if(data.obj){
			   	childList=data.obj;
			   	for (var i = 0; i < data.obj.length; i++) {
			   		doctorListsHTML+="<div class='doctor-list-content' userId='"+data.obj[i].userId+"'>"+
										"<div class='doctor-list-tab w100'>"+
											"<div class='doctor-head-image w20'><img src='"+data.obj[i].headimgurl+"'></div>"+
											"<div class='person-name w60 am-margin-left-xs'>"+
												"<p class='doctor-name-text color4e'>"+data.obj[i].doctorRealName+"</p>"+
												"<p class='doctor-comp'>"+data.obj[i].stationName+"</p>"+
												"<div class='doctor-desc'>"+
													"<p>"+data.obj[i].des+"</p>"+
												"</div>"+
											"</div>"+
											"<div class='contact-doctor am-text-right w40 line'>"+
												"<button>"+data.obj[i].douctorConsultTypeName+"</button>"+
											"</div>"+
										"</div>"+
									"</div>";
				}
			   	$('.doctor-list').append(doctorListsHTML);
			   }
			}
		});
	}
	getTJDcotors();
	getDoctorList();
	/*查询医生详细信息*/
	$('body').on('click','.doctor-vip .doctor-vip-content,.doctor-list .doctor-list-content',function(){
		var userId=$(this).attr('userId');
			ym.ajax({
				url: "/askDoctor/queryDoctorInfo",
				param:{
					userId:userId
				},
				success: function (data) {
				   if(data.obj){
				   		sessionStorage.setItem('curData',JSON.stringify(data.obj));
						window.location.href='askDoctor.html?a=0';
				   }
				}
			});
	})
})